<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script src="./jquery-3.4.1.min.js"></script>
  <script>
    const p1 = Promise.resolve(1)
    const p2 = Promise.resolve(278947234823742389)
    const p3 = Promise.resolve(1231)

    //Promise.all() 同时执行多个异步操作 一起返回异步操作
    // 返回的结果时按顺序返回
    // Promise.all([p1, p2, p3]).then(res => {
    //   console.log(res[0])
    //   console.log(res[1])
    //   console.log(res[2])
    // })
    Promise.all([$.ajax({ url: "./1.js" }), $.ajax({ url: "./2.js" }), $.ajax({ url: "./3.js" })]).then(res => {
      console.log(res)
    })
    const ps1 = () => {
      return new Promise((resolve, rejcet) => {
        setTimeout(() => {
          resolve("ps1的数据")
        }, 5000)
      })
    }
    const ps2 = () => {
      return new Promise((resolve, rejcet) => {
        setTimeout(() => {
          resolve("ps2的数据")
        }, 3000)
      })
    }
    // Promise.race()
    // 竞争请求  同时请求多个异步操作  哪个异步操作先完成用哪个
    Promise.race([ps1(), ps2()]).then(res => {
      console.log(res)
    })

  </script>
</body>

</html>